package com.tianxiao.faas.application.web.corner;

import com.tianxiao.faas.api.param.corner.*;
import com.tianxiao.faas.biz.service.corner.RankingService;
import com.tianxiao.faas.common.access.Access;
import com.tianxiao.faas.common.result.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/admin/ranking/")
public class RankingAdminController {

    @Resource
    private RankingService rankingService;

    @RequestMapping(value = "/save")
    @Access(access = {"admin"})
    public Result<Boolean> save(@RequestBody RankingSaveParam param) {
        rankingService.save(param);
        return Result.builder().success(true).data(true);

    }

    @RequestMapping(value = "/shop/list")
    @Access(access = {"admin"})
    public Result<List<RankingShopResult>> shopList(@RequestBody RankingShopListPageParam param) {
        Integer type = 1;
        List<RankingShopResult> results = rankingService.shopList(param, type);
        return Result.builder().success(true).data(results).totalCount(results.size()).pageNo(param.getPage())
                .pageSize(param.getPageSize()).totalPage();
    }

    @RequestMapping(value = "/goods/list")
    @Access(access = {"admin"})
    public Result<List<RankingGoodsResult>> goodsList(@RequestBody BasePageParam param) {
        Integer type = 2;
        List<RankingGoodsResult> results = rankingService.goodsList(param, type);
        return Result.builder().success(true).data(results).totalCount(results.size()).pageNo(param.getPage())
                .pageSize(param.getPageSize()).totalPage();
    }

    @RequestMapping(value = "/delete")
    @Access(access = {"admin"})
    public Result<Boolean> delete(Long id) {
        rankingService.delete(id);
        return Result.builder().success(true).data(true);

    }
}
